﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Taula = DeltaFlex.Negoci.ConsTaules.Concepte_OT;

namespace DeltaFlex.Negoci
{
    [Serializable()]
    public class Concepte_OT
    {
        #region Variables
        private int _idConcepte_OT;
        private int _idOrdre;
        private int _quantitat;
        private Articles _article;
        private decimal _ample;
        private decimal _alt;
        private decimal _import;
        #endregion

        #region Atributs
        public int IdConcepte_OT
        {
            get { return _idConcepte_OT; }
            set {_idConcepte_OT = value;}
        }

        public int IdOrdre
        {
            get { return _idOrdre; }
            set { _idOrdre = value; }
        }

        public int Quantitat
        {
            get { return _quantitat; }
            set { _quantitat = value; }
        }

       public Articles Article
        {
            get { return _article; }
            set { _article = value; }
        }
        public decimal Alt
        {
            get { return _alt; }
            set { _alt = value; }
        }

        public decimal Ample
        {
            get { return _ample; }
            set { _ample = value; }
        }

        public decimal Import
        {
            get { return _import; }
            set { _import = value; }
        }
        #endregion

        #region Inserts
        public static int InsertarConcepte_OT(int idOrdre, int quantitat, int idArticle, decimal ample,decimal alt, decimal import)
        {
            try
            {
                return Data.Concepte_OT.InsertarConcepte_OT(idOrdre, quantitat, idArticle, ample, alt, import);
            }
            catch { throw; }
        }
        #endregion

        #region Selects
        public static List<Concepte_OT> LlistarConcepteByIdOrdre(int idOrdre)
        {
            List<Concepte_OT> lstConcepte_OT = new List<Concepte_OT>();
            IDataReader reader = null;

            try
            {
                reader = Data.Concepte_OT.LlistarConceptes_OTByIdOrdre(idOrdre);

                while (reader.Read())
                {
                    lstConcepte_OT.Add(MapEntityFromDataReader(reader));
                }
            }
            catch { throw; }
            finally
            {
                if (reader != null) reader.Close();
            }

            return lstConcepte_OT;
        }
        #endregion

        #region Update
        public static void ActualitzarConcepte_OT(int idConcepte, int quantitat, int idArticle, decimal ample, decimal alt, decimal import)
        {
            try
            {
                Data.Concepte_OT.ActualitzarConcepte_OT(idConcepte, quantitat, idArticle, ample, alt, import);
            }
            catch { throw; }
        }
        #endregion

        #region Mapeig
        public static Concepte_OT MapEntityFromDataReader(IDataReader record)
        {
            Concepte_OT concepte_OT = new Concepte_OT();

            MemberAllocation.Allocate(record, Taula.COLUMNA_IDCONCEPTE, ref concepte_OT._idConcepte_OT);
            MemberAllocation.Allocate(record, Taula.COLUMNA_IDORDRE, ref concepte_OT._idOrdre);
            MemberAllocation.Allocate(record, Taula.COLUMNA_QUANTITAT, ref concepte_OT._quantitat);
            concepte_OT._article = Articles.MapEntityFromDataReader(record);
            MemberAllocation.Allocate(record, Taula.COLUMNA_ALT, ref concepte_OT._alt);
            MemberAllocation.Allocate(record, Taula.COLUMNA_AMPLE, ref concepte_OT._ample);
            MemberAllocation.Allocate(record, Taula.COLUMNA_IMPORT, ref concepte_OT._import);

            return concepte_OT;
        }
        #endregion

    }
}
